﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace VGTimer.Common
{
    public class PerformanceTimer
    {
        public PerformanceTimer()
        {
        }


        public static async Task Delay(int time)
        {
            await Task.Run(() =>
            {
                QueryPerformanceCounter(out long startTime);

                while (true)
                {
                    QueryPerformanceCounter(out long nowTime);
                    if ((nowTime - startTime) / 10000 >= time)
                    {
                        return;
                    }
                }
            });
        }

        [DllImport("kernel32")]
        static extern bool QueryPerformanceFrequency(out long PerformanceFrequency);
        [DllImport("kernel32")]
        static extern bool QueryPerformanceCounter(out long PerformanceCounter);
    }
}
